﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Web.Services;
using System.Web;
using System.Data;
using System.Configuration;
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;
using System.Data.SqlClient;
using System.Drawing;
using System.Net.Mail;

using System.Web.Services;

using System.IO.MemoryMappedFiles;


public partial class admin_partner_partner_add_request : System.Web.UI.Page
{
    string r_id = null;
    protected void Page_Load(object sender, EventArgs e)
    {




        Label1.Text = Session["email"].ToString();
        txtcreate.Text = System.DateTime.Now.ToString();
        txtagent.Text = Session["email"].ToString();


    }


    //[WebMethod]

    //public static string InsertMethod(string from1, string upto, string from2, string upto2, string from3, string upto3, string budget, string storage, string sun_balcony, string balcony, string parking, string ac, string shelter, string personal_zone, string street, string city, string neghrhood,string no_nghrhood,string area,string comment,string terms,string cat,string c_cat)
    //{

    //    SqlConnection conn = null;
    //    conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString);
    //    {
    //        SqlCommand cmd = new SqlCommand("Insert into request5 values('" + from1 + "', '" + upto + "', '" + from2 + "', '" + upto2 + "', '" + from3 + "', '" + upto3 + "', '" + budget + "', '" + storage + "', '" + sun_balcony + "', '" + balcony + "', '" + parking + "', '" + ac + "', '" + shelter + "', '" + personal_zone + "', '" + street + "', '" + city + "', '" + neghrhood + "','" + no_nghrhood + "','" + area + "','" + comment + "','" + terms + "','" + cat + "','" + c_cat +"')", conn);
    //        {
    //            conn.Open();
    //            cmd.ExecuteNonQuery();
    //            return "True";
    //        }
    //    }
    //}
    protected void Save1_Click(object sender, EventArgs e)
    {
        string cat = null;
        cat = txtchooseaddress.SelectedValue;
        SqlConnection conn = null;
        conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString);
        conn.Open();



        if (cat.Equals("handled by office"))
        {
            Random r1 = new Random();
            int num = r1.Next(0, 99999999); // generate random number
            string number = string.Format("{0:D8}", num);

            Random r2 = new Random();
            int num2 = r2.Next(0, 26); // generate random letter
            char letter = (char)('A' + num2);


            r_id = number + letter; // join both as ID 

            SqlCommand cmd = new SqlCommand("Insert into request5 values(@r_id,@c_id,@from1,@upto,@from2,@upto2,@from3,@upto3,@budget,@storage,@sun_balcony ,@balcony,@parking,@ac,@shelter,@personal_zone, @street,@city,@neghrhood,@no_nghrhood,@area, @comment,@terms,@cat,@c_cat,@fast_update,@renew,@status1,@added)", conn);
            cmd.Parameters.AddWithValue("@r_id", r_id);
            cmd.Parameters.AddWithValue("@c_id", DropDownList3.SelectedValue);
            cmd.Parameters.AddWithValue("@from1", txtfrom1.Text);
            cmd.Parameters.AddWithValue("@upto", txtupto1.Text);
            cmd.Parameters.AddWithValue("@from2", txtfrom.Text);
            cmd.Parameters.AddWithValue("@upto2", txtupto.Text);
            cmd.Parameters.AddWithValue("@from3", from.Text);
            cmd.Parameters.AddWithValue("@upto3", txtupto3.Text);
            cmd.Parameters.AddWithValue("@budget", txtbudget.Text);
            cmd.Parameters.AddWithValue("@storage", txtstorage.SelectedValue);
            cmd.Parameters.AddWithValue("@sun_balcony", txtsunbalcony.SelectedValue);
            cmd.Parameters.AddWithValue("@balcony", txtbalcony.SelectedValue);
            cmd.Parameters.AddWithValue("@parking", txtparking.SelectedValue);
            cmd.Parameters.AddWithValue("@ac", txtac.SelectedValue);
            cmd.Parameters.AddWithValue("@shelter", txtshelter.SelectedValue);
            cmd.Parameters.AddWithValue("@personal_zone", txtperzone.SelectedValue);
            cmd.Parameters.AddWithValue("@street", txtstreet.SelectedValue);
            cmd.Parameters.AddWithValue("@city", txtcity.SelectedValue);
            cmd.Parameters.AddWithValue("@neghrhood", txtnghr.SelectedValue);
            cmd.Parameters.AddWithValue("@no_nghrhood", txtnongr.SelectedValue);
            cmd.Parameters.AddWithValue("@area", txtarea.SelectedValue);
            cmd.Parameters.AddWithValue("@comment", txtcomment.Text);
            cmd.Parameters.AddWithValue("@terms", txtterms.Text);
            cmd.Parameters.AddWithValue("@cat", txtchooseaddress.Text);
            cmd.Parameters.AddWithValue("@c_cat", txtcat6.Text);
            cmd.Parameters.AddWithValue("@fast_update", DropDownList2.SelectedValue);
            cmd.Parameters.AddWithValue("@renew", TextBox1.Text);
            cmd.Parameters.AddWithValue("@status1", "0");
            cmd.Parameters.AddWithValue("@added", Session["email"]);
            // cmd.Parameters.AddWithValue("@update", DropDownList2 .SelectedValue );



            cmd.ExecuteNonQuery();
            Session["cr_id"] = r_id;
            //Response.Redirect("request_confirmation.aspx?=" + r_id.Trim());

        }
        else if (cat.Equals("signed and handled by office"))
        {
            Random r1 = new Random();
            int num = r1.Next(0, 99999999); // generate random number
            string number = string.Format("{0:D8}", num);

            Random r2 = new Random();
            int num2 = r2.Next(0, 26); // generate random letter
            char letter = (char)('A' + num2);


            r_id = number + letter; // join both as ID 

            SqlCommand cmd = new SqlCommand("Insert into request5 values(@r_id,@c_id,@from1,@upto,@from2,@upto2,@from3,@upto3,@budget,@storage,@sun_balcony ,@balcony,@parking,@ac,@shelter,@personal_zone, @street,@city,@neghrhood,@no_nghrhood,@area, @comment,@terms,@cat,@c_cat,@fast_update,@renew,@status1,@added)", conn);
            cmd.Parameters.AddWithValue("@r_id", r_id);
            cmd.Parameters.AddWithValue("@c_id", DropDownList3.SelectedValue);
            cmd.Parameters.AddWithValue("@from1", txtfrom1.Text);
            cmd.Parameters.AddWithValue("@upto", txtupto1.Text);
            cmd.Parameters.AddWithValue("@from2", txtfrom.Text);
            cmd.Parameters.AddWithValue("@upto2", txtupto.Text);
            cmd.Parameters.AddWithValue("@from3", from.Text);
            cmd.Parameters.AddWithValue("@upto3", txtupto3.Text);
            cmd.Parameters.AddWithValue("@budget", txtbudget.Text);
            cmd.Parameters.AddWithValue("@storage", txtstorage.SelectedValue);
            cmd.Parameters.AddWithValue("@sun_balcony", txtsunbalcony.SelectedValue);
            cmd.Parameters.AddWithValue("@balcony", txtbalcony.SelectedValue);
            cmd.Parameters.AddWithValue("@parking", txtparking.SelectedValue);
            cmd.Parameters.AddWithValue("@ac", txtac.SelectedValue);
            cmd.Parameters.AddWithValue("@shelter", txtshelter.SelectedValue);
            cmd.Parameters.AddWithValue("@personal_zone", txtperzone.SelectedValue);
            cmd.Parameters.AddWithValue("@street", txtstreet.SelectedValue);
            cmd.Parameters.AddWithValue("@city", txtcity.SelectedValue);
            cmd.Parameters.AddWithValue("@neghrhood", txtnghr.SelectedValue);
            cmd.Parameters.AddWithValue("@no_nghrhood", txtnongr.SelectedValue);
            cmd.Parameters.AddWithValue("@area", txtarea.SelectedValue);
            cmd.Parameters.AddWithValue("@comment", txtcomment.Text);
            cmd.Parameters.AddWithValue("@terms", txtterms.Text);
            cmd.Parameters.AddWithValue("@cat", txtchooseaddress.Text);
            cmd.Parameters.AddWithValue("@c_cat", txtcat2.Text);

            cmd.Parameters.AddWithValue("@fast_update", "no");
            cmd.Parameters.AddWithValue("@renew", "no");
            cmd.Parameters.AddWithValue("@status1", "0");
            cmd.Parameters.AddWithValue("@added", Session["email"]);
            //cmd.Parameters.AddWithValue("@update", "0");
            cmd.ExecuteNonQuery();
            Session["cr_id"] = r_id;
            //Response.Redirect("request_confirmation.aspx?=" + r_id.Trim());

        }

        else if (cat.Equals("advanced negotiation"))
        {
            Random r1 = new Random();
            int num = r1.Next(0, 99999999); // generate random number
            string number = string.Format("{0:D8}", num);

            Random r2 = new Random();
            int num2 = r2.Next(0, 26); // generate random letter
            char letter = (char)('A' + num2);


            r_id = number + letter; // join both as ID 
            SqlCommand cmd = new SqlCommand("Insert into request5 values(@r_id,@c_id,@from1,@upto,@from2,@upto2,@from3,@upto3,@budget,@storage,@sun_balcony ,@balcony,@parking,@ac,@shelter,@personal_zone, @street,@city,@neghrhood,@no_nghrhood,@area, @comment,@terms,@cat,@c_cat,@fast_update,@renew,@status1,@added )", conn);
            cmd.Parameters.AddWithValue("@r_id", r_id);
            cmd.Parameters.AddWithValue("@c_id", DropDownList3.SelectedValue);
            cmd.Parameters.AddWithValue("@from1", txtfrom1.Text);
            cmd.Parameters.AddWithValue("@upto", txtupto1.Text);
            cmd.Parameters.AddWithValue("@from2", txtfrom.Text);
            cmd.Parameters.AddWithValue("@upto2", txtupto.Text);
            cmd.Parameters.AddWithValue("@from3", from.Text);
            cmd.Parameters.AddWithValue("@upto3", txtupto3.Text);
            cmd.Parameters.AddWithValue("@budget", txtbudget.Text);
            cmd.Parameters.AddWithValue("@storage", txtstorage.SelectedValue);
            cmd.Parameters.AddWithValue("@sun_balcony", txtsunbalcony.SelectedValue);
            cmd.Parameters.AddWithValue("@balcony", txtbalcony.SelectedValue);
            cmd.Parameters.AddWithValue("@parking", txtparking.SelectedValue);
            cmd.Parameters.AddWithValue("@ac", txtac.SelectedValue);
            cmd.Parameters.AddWithValue("@shelter", txtshelter.SelectedValue);
            cmd.Parameters.AddWithValue("@personal_zone", txtperzone.SelectedValue);
            cmd.Parameters.AddWithValue("@street", txtstreet.SelectedValue);
            cmd.Parameters.AddWithValue("@city", txtcity.SelectedValue);
            cmd.Parameters.AddWithValue("@neghrhood", txtnghr.SelectedValue);
            cmd.Parameters.AddWithValue("@no_nghrhood", txtnongr.SelectedValue);
            cmd.Parameters.AddWithValue("@area", txtarea.SelectedValue);
            cmd.Parameters.AddWithValue("@comment", txtcomment.Text);
            cmd.Parameters.AddWithValue("@terms", txtterms.Text);
            cmd.Parameters.AddWithValue("@cat", txtchooseaddress.Text);
            cmd.Parameters.AddWithValue("@c_cat", txtcatname3.Text);

            cmd.Parameters.AddWithValue("@fast_update", "no");
            cmd.Parameters.AddWithValue("@renew", "no");
            cmd.Parameters.AddWithValue("@status1", "0");
            cmd.Parameters.AddWithValue("@added", Session["email"]);
            //  cmd.Parameters.AddWithValue("@update", "0");

            cmd.ExecuteNonQuery();
            //Response.Redirect("request_confirmation.aspx?=" + r_id.Trim());

        }

        else if (cat.Equals("freezed"))
        {
            Random r1 = new Random();
            int num = r1.Next(0, 99999999); // generate random number
            string number = string.Format("{0:D8}", num);

            Random r2 = new Random();
            int num2 = r2.Next(0, 26); // generate random letter
            char letter = (char)('A' + num2);


            r_id = number + letter; // join both as ID 
            SqlCommand cmd = new SqlCommand("Insert into request5 values(@r_id,@c_id,@from1,@upto,@from2,@upto2,@from3,@upto3,@budget,@storage,@sun_balcony ,@balcony,@parking,@ac,@shelter,@personal_zone, @street,@city,@neghrhood,@no_nghrhood,@area, @comment,@terms,@cat,@c_cat,@fast_update,@renew,@status1,@added)", conn);
            cmd.Parameters.AddWithValue("@r_id", r_id);
            cmd.Parameters.AddWithValue("@c_id", DropDownList3.SelectedValue);
            cmd.Parameters.AddWithValue("@from1", txtfrom1.Text);
            cmd.Parameters.AddWithValue("@upto", txtupto1.Text);
            cmd.Parameters.AddWithValue("@from2", txtfrom.Text);
            cmd.Parameters.AddWithValue("@upto2", txtupto.Text);
            cmd.Parameters.AddWithValue("@from3", from.Text);
            cmd.Parameters.AddWithValue("@upto3", txtupto3.Text);
            cmd.Parameters.AddWithValue("@budget", txtbudget.Text);
            cmd.Parameters.AddWithValue("@storage", txtstorage.SelectedValue);
            cmd.Parameters.AddWithValue("@sun_balcony", txtsunbalcony.SelectedValue);
            cmd.Parameters.AddWithValue("@balcony", txtbalcony.SelectedValue);
            cmd.Parameters.AddWithValue("@parking", txtparking.SelectedValue);
            cmd.Parameters.AddWithValue("@ac", txtac.SelectedValue);
            cmd.Parameters.AddWithValue("@shelter", txtshelter.SelectedValue);
            cmd.Parameters.AddWithValue("@personal_zone", txtperzone.SelectedValue);
            cmd.Parameters.AddWithValue("@street", txtstreet.SelectedValue);
            cmd.Parameters.AddWithValue("@city", txtcity.SelectedValue);
            cmd.Parameters.AddWithValue("@neghrhood", txtnghr.SelectedValue);
            cmd.Parameters.AddWithValue("@no_nghrhood", txtnongr.SelectedValue);
            cmd.Parameters.AddWithValue("@area", txtarea.SelectedValue);
            cmd.Parameters.AddWithValue("@comment", txtcomment.Text);
            cmd.Parameters.AddWithValue("@terms", txtterms.Text);
            cmd.Parameters.AddWithValue("@cat", txtchooseaddress.Text);
            cmd.Parameters.AddWithValue("@c_cat", catgname4.Text);

            cmd.Parameters.AddWithValue("@fast_update", "no");
            cmd.Parameters.AddWithValue("@renew", "no");
            cmd.Parameters.AddWithValue("@status1", "0");
            cmd.Parameters.AddWithValue("@added", Session["email"]);



            // cmd.Parameters.AddWithValue("@update", "0");


            cmd.ExecuteNonQuery();
            //Response.Redirect("request_confirmation.aspx?=" + r_id.Trim());

        }
        else if (cat.Equals("not interested"))
        {
            Random r1 = new Random();
            int num = r1.Next(0, 99999999); // generate random number
            string number = string.Format("{0:D8}", num);

            Random r2 = new Random();
            int num2 = r2.Next(0, 26); // generate random letter
            char letter = (char)('A' + num2);


            r_id = number + letter; // join both as ID 
            SqlCommand cmd = new SqlCommand("Insert into request5 values(@r_id,@c_id,@from1,@upto,@from2,@upto2,@from3,@upto3,@budget,@storage,@sun_balcony ,@balcony,@parking,@ac,@shelter,@personal_zone, @street,@city,@neghrhood,@no_nghrhood,@area, @comment,@terms,@cat,@c_cat,@fast_update,@renew,@status1,@added)", conn);
            cmd.Parameters.AddWithValue("@r_id", r_id);
            cmd.Parameters.AddWithValue("@c_id", DropDownList3.SelectedValue);
            cmd.Parameters.AddWithValue("@from1", txtfrom1.Text);
            cmd.Parameters.AddWithValue("@upto", txtupto1.Text);
            cmd.Parameters.AddWithValue("@from2", txtfrom.Text);
            cmd.Parameters.AddWithValue("@upto2", txtupto.Text);
            cmd.Parameters.AddWithValue("@from3", from.Text);
            cmd.Parameters.AddWithValue("@upto3", txtupto3.Text);
            cmd.Parameters.AddWithValue("@budget", txtbudget.Text);
            cmd.Parameters.AddWithValue("@storage", txtstorage.SelectedValue);
            cmd.Parameters.AddWithValue("@sun_balcony", txtsunbalcony.SelectedValue);
            cmd.Parameters.AddWithValue("@balcony", txtbalcony.SelectedValue);
            cmd.Parameters.AddWithValue("@parking", txtparking.SelectedValue);
            cmd.Parameters.AddWithValue("@ac", txtac.SelectedValue);
            cmd.Parameters.AddWithValue("@shelter", txtshelter.SelectedValue);
            cmd.Parameters.AddWithValue("@personal_zone", txtperzone.SelectedValue);
            cmd.Parameters.AddWithValue("@street", txtstreet.SelectedValue);
            cmd.Parameters.AddWithValue("@city", txtcity.SelectedValue);
            cmd.Parameters.AddWithValue("@neghrhood", txtnghr.SelectedValue);
            cmd.Parameters.AddWithValue("@no_nghrhood", txtnongr.SelectedValue);
            cmd.Parameters.AddWithValue("@area", txtarea.SelectedValue);
            cmd.Parameters.AddWithValue("@comment", txtcomment.Text);
            cmd.Parameters.AddWithValue("@terms", txtterms.Text);
            cmd.Parameters.AddWithValue("@cat", txtchooseaddress.Text);
            cmd.Parameters.AddWithValue("@c_cat", txtcat5.Text);
            cmd.Parameters.AddWithValue("@fast_update", "no");
            cmd.Parameters.AddWithValue("@renew", "no");
            cmd.Parameters.AddWithValue("@status1", "0");
            cmd.Parameters.AddWithValue("@added", Session["email"]);
            // cmd.Parameters.AddWithValue("@update", "0");


            cmd.ExecuteNonQuery();
            //Response.Redirect("request_confirmation.aspx?=" + r_id.Trim());

        }
        else if (cat.Equals("canceled"))
        {
            Random r1 = new Random();
            int num = r1.Next(0, 99999999); // generate random number
            string number = string.Format("{0:D8}", num);

            Random r2 = new Random();
            int num2 = r2.Next(0, 26); // generate random letter
            char letter = (char)('A' + num2);


            r_id = number + letter; // join both as ID 
            SqlCommand cmd = new SqlCommand("Insert into request5 values(@r_id,@c_id,@from1,@upto,@from2,@upto2,@from3,@upto3,@budget,@storage,@sun_balcony ,@balcony,@parking,@ac,@shelter,@personal_zone, @street,@city,@neghrhood,@no_nghrhood,@area, @comment,@terms,@cat,@c_cat ,@fast_update,@renew,@status1,@added)", conn);
            cmd.Parameters.AddWithValue("@r_id", r_id);
            cmd.Parameters.AddWithValue("@c_id", DropDownList3.SelectedValue);
            cmd.Parameters.AddWithValue("@from1", txtfrom1.Text);
            cmd.Parameters.AddWithValue("@upto", txtupto1.Text);
            cmd.Parameters.AddWithValue("@from2", txtfrom.Text);
            cmd.Parameters.AddWithValue("@upto2", txtupto.Text);
            cmd.Parameters.AddWithValue("@from3", from.Text);
            cmd.Parameters.AddWithValue("@upto3", txtupto3.Text);
            cmd.Parameters.AddWithValue("@budget", txtbudget.Text);
            cmd.Parameters.AddWithValue("@storage", txtstorage.SelectedValue);
            cmd.Parameters.AddWithValue("@sun_balcony", txtsunbalcony.SelectedValue);
            cmd.Parameters.AddWithValue("@balcony", txtbalcony.SelectedValue);
            cmd.Parameters.AddWithValue("@parking", txtparking.SelectedValue);
            cmd.Parameters.AddWithValue("@ac", txtac.SelectedValue);
            cmd.Parameters.AddWithValue("@shelter", txtshelter.SelectedValue);
            cmd.Parameters.AddWithValue("@personal_zone", txtperzone.SelectedValue);
            cmd.Parameters.AddWithValue("@street", txtstreet.SelectedValue);
            cmd.Parameters.AddWithValue("@city", txtcity.SelectedValue);
            cmd.Parameters.AddWithValue("@neghrhood", txtnghr.SelectedValue);
            cmd.Parameters.AddWithValue("@no_nghrhood", txtnongr.SelectedValue);
            cmd.Parameters.AddWithValue("@area", txtarea.SelectedValue);
            cmd.Parameters.AddWithValue("@comment", txtcomment.Text);
            cmd.Parameters.AddWithValue("@terms", txtterms.Text);
            cmd.Parameters.AddWithValue("@cat", txtchooseaddress.Text);
            cmd.Parameters.AddWithValue("@c_cat", txtcat6.Text);
            cmd.Parameters.AddWithValue("@fast_update", "no");
            cmd.Parameters.AddWithValue("@renew", "no");
            cmd.Parameters.AddWithValue("@status1", "0");
            cmd.Parameters.AddWithValue("@added", Session["email"]);
            //   cmd.Parameters.AddWithValue("@update","0");


            cmd.ExecuteNonQuery();
            //Response.Redirect("request_confirmation.aspx?=" + r_id.Trim());

        }
        else if (cat.Equals("unknown"))
        {
            Random r1 = new Random();
            int num = r1.Next(0, 99999999); // generate random number
            string number = string.Format("{0:D8}", num);

            Random r2 = new Random();
            int num2 = r2.Next(0, 26); // generate random letter
            char letter = (char)('A' + num2);


            r_id = number + letter; // join both as ID 
            SqlCommand cmd = new SqlCommand("Insert into request5 values(@r_id,@c_id,@from1,@upto,@from2,@upto2,@from3,@upto3,@budget,@storage,@sun_balcony ,@balcony,@parking,@ac,@shelter,@personal_zone, @street,@city,@neghrhood,@no_nghrhood,@area, @comment,@terms,@cat,@c_cat,@fast_update,@renew,@status1,@added)", conn);
            cmd.Parameters.AddWithValue("@r_id", r_id);
            cmd.Parameters.AddWithValue("@c_id", DropDownList3.SelectedValue);
            cmd.Parameters.AddWithValue("@from1", txtfrom1.Text);
            cmd.Parameters.AddWithValue("@upto", txtupto1.Text);
            cmd.Parameters.AddWithValue("@from2", txtfrom.Text);
            cmd.Parameters.AddWithValue("@upto2", txtupto.Text);
            cmd.Parameters.AddWithValue("@from3", from.Text);
            cmd.Parameters.AddWithValue("@upto3", txtupto3.Text);
            cmd.Parameters.AddWithValue("@budget", txtbudget.Text);
            cmd.Parameters.AddWithValue("@storage", txtstorage.SelectedValue);
            cmd.Parameters.AddWithValue("@sun_balcony", txtsunbalcony.SelectedValue);
            cmd.Parameters.AddWithValue("@balcony", txtbalcony.SelectedValue);
            cmd.Parameters.AddWithValue("@parking", txtparking.SelectedValue);
            cmd.Parameters.AddWithValue("@ac", txtac.SelectedValue);
            cmd.Parameters.AddWithValue("@shelter", txtshelter.SelectedValue);
            cmd.Parameters.AddWithValue("@personal_zone", txtperzone.SelectedValue);
            cmd.Parameters.AddWithValue("@street", txtstreet.SelectedValue);
            cmd.Parameters.AddWithValue("@city", txtcity.SelectedValue);
            cmd.Parameters.AddWithValue("@neghrhood", txtnghr.SelectedValue);
            cmd.Parameters.AddWithValue("@no_nghrhood", txtnongr.SelectedValue);
            cmd.Parameters.AddWithValue("@area", txtarea.SelectedValue);
            cmd.Parameters.AddWithValue("@comment", txtcomment.Text);
            cmd.Parameters.AddWithValue("@terms", txtterms.Text);
            cmd.Parameters.AddWithValue("@cat", txtchooseaddress.Text);
            cmd.Parameters.AddWithValue("@c_cat", txtcatg7.Text);
            cmd.Parameters.AddWithValue("@fast_update", "no");
            cmd.Parameters.AddWithValue("@renew", "no");
            cmd.Parameters.AddWithValue("@status1", "0");
            cmd.Parameters.AddWithValue("@added", Session["email"]);
            // cmd.Parameters.AddWithValue("@update", "0");


            cmd.ExecuteNonQuery();
            //Response.Redirect("request_confirmation.aspx?=" + r_id.Trim());
        }
        else if (cat.Equals("transaction signed"))
        {
            Random r1 = new Random();
            int num = r1.Next(0, 99999999); // generate random number
            string number = string.Format("{0:D8}", num);

            Random r2 = new Random();
            int num2 = r2.Next(0, 26); // generate random letter
            char letter = (char)('A' + num2);


            r_id = number + letter; // join both as ID 
            SqlCommand cmd = new SqlCommand("Insert into request5 values(@r_id,@c_id,@from1,@upto,@from2,@upto2,@from3,@upto3,@budget,@storage,@sun_balcony ,@balcony,@parking,@ac,@shelter,@personal_zone, @street,@city,@neghrhood,@no_nghrhood,@area, @comment,@terms,@cat,@c_cat, @fast_update,@renew,@status1,@added)", conn);
            cmd.Parameters.AddWithValue("@r_id", r_id);
            cmd.Parameters.AddWithValue("@c_id", DropDownList3.SelectedValue);
            cmd.Parameters.AddWithValue("@from1", txtfrom1.Text);
            cmd.Parameters.AddWithValue("@upto", txtupto1.Text);
            cmd.Parameters.AddWithValue("@from2", txtfrom.Text);
            cmd.Parameters.AddWithValue("@upto2", txtupto.Text);
            cmd.Parameters.AddWithValue("@from3", from.Text);
            cmd.Parameters.AddWithValue("@upto3", txtupto3.Text);
            cmd.Parameters.AddWithValue("@budget", txtbudget.Text);
            cmd.Parameters.AddWithValue("@storage", txtstorage.SelectedValue);
            cmd.Parameters.AddWithValue("@sun_balcony", txtsunbalcony.SelectedValue);
            cmd.Parameters.AddWithValue("@balcony", txtbalcony.SelectedValue);
            cmd.Parameters.AddWithValue("@parking", txtparking.SelectedValue);
            cmd.Parameters.AddWithValue("@ac", txtac.SelectedValue);
            cmd.Parameters.AddWithValue("@shelter", txtshelter.SelectedValue);
            cmd.Parameters.AddWithValue("@personal_zone", txtperzone.SelectedValue);
            cmd.Parameters.AddWithValue("@street", txtstreet.SelectedValue);
            cmd.Parameters.AddWithValue("@city", txtcity.SelectedValue);
            cmd.Parameters.AddWithValue("@neghrhood", txtnghr.SelectedValue);
            cmd.Parameters.AddWithValue("@no_nghrhood", txtnongr.SelectedValue);
            cmd.Parameters.AddWithValue("@area", txtarea.SelectedValue);
            cmd.Parameters.AddWithValue("@comment", txtcomment.Text);
            cmd.Parameters.AddWithValue("@terms", txtterms.Text);
            cmd.Parameters.AddWithValue("@cat", txtchooseaddress.Text);
            cmd.Parameters.AddWithValue("@c_cat", txtcat8.Text);
            cmd.Parameters.AddWithValue("@fast_update", "no");
            cmd.Parameters.AddWithValue("@renew", "no");
            cmd.Parameters.AddWithValue("@status1", "0");
            cmd.Parameters.AddWithValue("@added", Session["email"]);
            //cmd.Parameters.AddWithValue("@update", "0");


            cmd.ExecuteNonQuery();
            //Response.Redirect("request_confirmation.aspx?=" + r_id.Trim());
        }
        else if (cat.Equals("transaction signed"))
        {
            Random r1 = new Random();
            int num = r1.Next(0, 99999999); // generate random number
            string number = string.Format("{0:D8}", num);

            Random r2 = new Random();
            int num2 = r2.Next(0, 26); // generate random letter
            char letter = (char)('A' + num2);


            r_id = number + letter; // join both as ID 
            SqlCommand cmd = new SqlCommand("Insert into request5 values(@r_id,@c_id,@from1,@upto,@from2,@upto2,@from3,@upto3,@budget,@storage,@sun_balcony ,@balcony,@parking,@ac,@shelter,@personal_zone, @street,@city,@neghrhood,@no_nghrhood,@area, @comment,@terms,@cat,@c_cat,@fast_update,@renew,@status1,@added)", conn);
            cmd.Parameters.AddWithValue("@r_id", r_id);
            cmd.Parameters.AddWithValue("@c_id", DropDownList3.SelectedValue);
            cmd.Parameters.AddWithValue("@from1", txtfrom1.Text);
            cmd.Parameters.AddWithValue("@upto", txtupto1.Text);
            cmd.Parameters.AddWithValue("@from2", txtfrom.Text);
            cmd.Parameters.AddWithValue("@upto2", txtupto.Text);
            cmd.Parameters.AddWithValue("@from3", from.Text);
            cmd.Parameters.AddWithValue("@upto3", txtupto3.Text);
            cmd.Parameters.AddWithValue("@budget", txtbudget.Text);
            cmd.Parameters.AddWithValue("@storage", txtstorage.SelectedValue);
            cmd.Parameters.AddWithValue("@sun_balcony", txtsunbalcony.SelectedValue);
            cmd.Parameters.AddWithValue("@balcony", txtbalcony.SelectedValue);
            cmd.Parameters.AddWithValue("@parking", txtparking.SelectedValue);
            cmd.Parameters.AddWithValue("@ac", txtac.SelectedValue);
            cmd.Parameters.AddWithValue("@shelter", txtshelter.SelectedValue);
            cmd.Parameters.AddWithValue("@personal_zone", txtperzone.SelectedValue);
            cmd.Parameters.AddWithValue("@street", txtstreet.SelectedValue);
            cmd.Parameters.AddWithValue("@city", txtcity.SelectedValue);
            cmd.Parameters.AddWithValue("@neghrhood", txtnghr.SelectedValue);
            cmd.Parameters.AddWithValue("@no_nghrhood", txtnongr.SelectedValue);
            cmd.Parameters.AddWithValue("@area", txtarea.SelectedValue);
            cmd.Parameters.AddWithValue("@comment", txtcomment.Text);
            cmd.Parameters.AddWithValue("@terms", txtterms.Text);
            cmd.Parameters.AddWithValue("@cat", txtchooseaddress.Text);
            cmd.Parameters.AddWithValue("@c_cat", txtcat8.Text);
            cmd.Parameters.AddWithValue("@fast_update", "no");
            cmd.Parameters.AddWithValue("@renew", "no");
            cmd.Parameters.AddWithValue("@status1", "0");
            cmd.Parameters.AddWithValue("@added", Session["email"]);
            // cmd.Parameters.AddWithValue("@update", "0");



            cmd.ExecuteNonQuery();

            //Response.Redirect("request_confirmation.aspx?=" + r_id.Trim());
        }

        else
        {

        }
        if (FileUpload1.HasFile)
        {

            string fileName = Path.GetFileName(FileUpload1.PostedFile.FileName);

            string fileExtension = Path.GetExtension(FileUpload1.PostedFile.FileName);

            string documentType = string.Empty;



            //provide document type based on it's extension

            switch (fileExtension)
            {

                case ".pdf":

                    documentType = "application/pdf";

                    break;

                case ".xls":

                    documentType = "application/vnd.ms-excel";

                    break;

                case ".xlsx":

                    documentType = "application/vnd.ms-excel";

                    break;

                case ".doc":

                    documentType = "application/vnd.ms-word";

                    break;

                case ".docx":

                    documentType = "application/vnd.ms-word";

                    break;

                case ".gif":

                    documentType = "image/gif";

                    break;

                case ".png":

                    documentType = "image/png";

                    break;

                case ".jpg":

                    documentType = "image/jpg";

                    break;

            }



            //Calculate size of file to be uploaded

            int fileSize = FileUpload1.PostedFile.ContentLength;



            //Create array and read the file into it

            byte[] documentBinary = new byte[fileSize];

            FileUpload1.PostedFile.InputStream.Read(documentBinary, 0, fileSize);
            SqlConnection conn2 = null;
            conn2 = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString);
            conn2.Open();
            //SqlCommand cmd1 = new SqlCommand("insert into task values(@action_,@c_id ,@added_by, @c_name,@to_do ,@created ,@updated,@agent,@sec_agent,@DocName,@Type_,@DocData,@rank_,@commission,@refer,@comment)", conn2);
            SqlCommand cmd1 = new SqlCommand("insert into task values(@action_,@c_id ,@added_by, @c_name,@to_do ,@created ,@updated,@fast_reminder,@agent,@sec_agent,@rank_,@commission,@refer,@comment,@DocName,@Type_,@DocData)", conn2);
            cmd1.Parameters.AddWithValue("@action_", "0");
            cmd1.Parameters.AddWithValue("@c_id", DropDownList3.SelectedValue);
            cmd1.Parameters.AddWithValue("@added_by", Session["email"]);

            cmd1.Parameters.AddWithValue("@c_name", DropDownList6.SelectedValue);
            cmd1.Parameters.AddWithValue("@to_do", DropDownList4.SelectedValue);
            cmd1.Parameters.AddWithValue("@created", txtcreate.Text);
            cmd1.Parameters.AddWithValue("@updated", txtupdate.Text);
            cmd1.Parameters.AddWithValue("@fast_reminder", txtreminder.Text);
            cmd1.Parameters.AddWithValue("@agent", txtagent.Text);
            cmd1.Parameters.AddWithValue("@sec_agent", DropDownList6.SelectedValue);
            cmd1.Parameters.AddWithValue("@rank_", txtrank.Text);
            cmd1.Parameters.AddWithValue("@commission", txtagent.Text);
            cmd1.Parameters.AddWithValue("@refer", TextBox2.Text);
            cmd1.Parameters.AddWithValue("@comment", txtcomment.Text);
            SqlParameter DocName = new SqlParameter("@DocName", SqlDbType.VarChar, 50);

            DocName.Value = fileName.ToString();

            cmd1.Parameters.Add(DocName);
            SqlParameter Type = new SqlParameter("@Type_", SqlDbType.VarChar, 50);

            Type.Value = documentType.ToString();

            cmd1.Parameters.Add(Type);



            SqlParameter uploadedDocument = new SqlParameter("@DocData", SqlDbType.Binary, fileSize);

            uploadedDocument.Value = documentBinary;

            cmd1.Parameters.Add(uploadedDocument);



            cmd1.ExecuteNonQuery();
            //cmd1.Parameters.AddWithValue("@action_", "0");
            //cmd1.Parameters.AddWithValue("@c_id", DropDownList1.SelectedValue);
            //cmd1.Parameters.AddWithValue("@added_by", Session["email"]);

            //cmd1.Parameters.AddWithValue("@c_name", DropDownList6.SelectedValue);
            //cmd1.Parameters.AddWithValue("@to_do", DropDownList4.SelectedValue);
            //cmd1.Parameters.AddWithValue("@created", txtcreate.Text);
            //cmd1.Parameters.AddWithValue("@updated", txtupdate.Text);
            //cmd1.Parameters.AddWithValue("@agent", txtagent.Text);
            //cmd1.Parameters.AddWithValue("@sec_agent", DropDownList6.SelectedValue);

            //SqlParameter DocName = new SqlParameter("@DocName", SqlDbType.VarChar, 50);

            //DocName.Value = fileName.ToString();
            ////Response.Redirect("property_add_confirmation.aspx");
            //cmd1.Parameters.Add(DocName);
            //SqlParameter Type = new SqlParameter("@Type_", SqlDbType.VarChar, 50);

            //Type.Value = documentType.ToString();

            //cmd1.Parameters.Add(Type);



            //SqlParameter uploadedDocument = new SqlParameter("@DocData", SqlDbType.Binary, fileSize);

            //uploadedDocument.Value = documentBinary;

            //cmd1.Parameters.Add(uploadedDocument);

            //cmd1.Parameters.AddWithValue("@rank_", txtrank.Text);
            //cmd1.Parameters.AddWithValue("@commission", txtagent.Text);
            //cmd1.Parameters.AddWithValue("@refer", TextBox2.Text);
            //cmd1.Parameters.AddWithValue("@comment", txtcomment.Text);

            //cmd1.ExecuteNonQuery();
            Response.Redirect("partner_request_confirm.aspx");
            //Label1.Text = Session["email_id"].ToString();


        }
    }
    //protected void gvUserInfo_RowCommand(object sender, GridViewCommandEventArgs e)
    //{

    //    if (e.CommandName == "active")
    //    {

    //        //Label1.Text = "hello";
    //        int index = Convert.ToSByte(e.CommandArgument);

    //        GridViewRow row = gvUserInfo.Rows[index];
    //        SqlDataAdapter adp = new SqlDataAdapter();
    //        SqlCommand cmd1 = new SqlCommand();
    //        DataSet ds = new DataSet();


    //        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Connstr"].ConnectionString);

    //        con.Open();

    //        SqlCommand objectvalue = new SqlCommand("", con);
    //        cmd1.Connection = con;



    //        SqlCommand dmc = new SqlCommand("insert into notes(c_id,f_name,notes,date_) values ('" + row.Cells[0].Text + "','" + row.Cells[1].Text + "','" + DropDownList5.SelectedValue + "','" + System.DateTime.Now + "')", con);

    //        dmc.ExecuteNonQuery();
    //        //cmd.Parameters.AddWithValue("@notes", DropDownList2.SelectedValue);

    //        con.Close();

    //        Response.Write(@"<script language='javascript'>alert('Cleint has been selected')</script>");

    //        // con.Close();


    //    }


    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        Session.Abandon();
        Response.Redirect("../partner.aspx");
    }


    protected void gvUserInfo_SelectedIndexChanged(object sender, System.EventArgs e)
    {

    }
}


